package com.qifan.energy.adapter;

import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qifan.energy.R;
import com.qifan.energy.bean.result.CouponItem;
import com.qifan.energy.util.UIUtils;

import java.util.List;

public class CouponListAdapter extends BaseQuickAdapter<CouponItem,BaseViewHolder> {

    public CouponListAdapter(@Nullable List<CouponItem> data) {
        super(R.layout.item_list_coupon, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CouponItem item) {
        CouponItem.CouponBean coupon = item.getCoupon();
        int amout = new Double(coupon.getAmount()).intValue();
        helper.setText(R.id.coupon_value_tv,String.valueOf(amout));
        LinearLayout contentBgLl =  (LinearLayout)helper.getView(R.id.content_bg_ll);
        TextView userNowTv =  (TextView)helper.getView(R.id.use_now_tv);
        helper.addOnClickListener(R.id.use_now_tv);
        switch (helper.getAdapterPosition()%4) {
            case 0:
                contentBgLl.setBackgroundResource(R.mipmap.icon_coupon_red);
                userNowTv.setTextColor(UIUtils.getColor(R.color.red2));
                userNowTv.setBackground(UIUtils.getDrawable(R.drawable.shape_stroke_redr15));
                break;
            case 1:
                contentBgLl.setBackgroundResource(R.mipmap.icon_coupon_blue);
                userNowTv.setTextColor(UIUtils.getColor(R.color.blue2));
                userNowTv.setBackground(UIUtils.getDrawable(R.drawable.shape_stroke_bluer15));
                break;
            case 2:
                contentBgLl.setBackgroundResource(R.mipmap.icon_coupon_purple);
                userNowTv.setTextColor(UIUtils.getColor(R.color.purple));
                userNowTv.setBackground(UIUtils.getDrawable(R.drawable.shape_stroke_purpler15));
                break;
            case 3:
                contentBgLl.setBackgroundResource(R.mipmap.icon_coupon_orange);
                userNowTv.setTextColor(UIUtils.getColor(R.color.orange2));
                userNowTv.setBackground(UIUtils.getDrawable(R.drawable.shape_stroke_oranger15));
                break;
        }
    }
}
